package com.google.agerasample.testapp;

import com.google.agerasample.ResourceTable;

import ohos.agp.components.*;
import ohos.app.Context;

import java.util.List;

public class NoteItemProvider extends RecycleItemProvider {
    private Context context;
    private List<Note> data;

    @Override
    public int getCount() {
        return data.size();
    }

    public NoteItemProvider(Context context, List<Note> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public Component getComponent(int position, Component convertView, ComponentContainer parent) {
        Component rootLayout =
                LayoutScatter.getInstance(context).parse(ResourceTable.Layout_list_item_note, null, false);
        if (!(rootLayout instanceof ComponentContainer)) {
            return null;
        }
        Text txt = (Text) rootLayout.findComponentById(ResourceTable.Id_txt);
        String note = data.get(position).getNote();
        txt.setText(note.substring(0, 1) + " " + note);
        return rootLayout;
    }
}
